Skip to main content

Run a Report with SQL Data in the Java RESTful Engine

This tutorial will guide you through running a document with SQL data through the Fluent Java RESTful Engines. It will cover the setup of the engine along with executing a request to run a document with SQL data and retrieving the document after the output has finished.

Before you begin, you will need to have a Java RESTful Engine setup. If you do not have a Java RESTful Engine setup, please refer to the below section on how to setup the RESTful Engine. If you already have a Java RESTful Engine setup you can skip to the next section.

Setup the RESTful Engine

There are two ways to setup the RESTful Engine.

  1. Docker Container
  2. Manaul Setup on a Tomcat Server

Docker Container

The instructions to setup the RESTful Engine via Docker Container can be found here.

Manual Setup on a Tomcat Server

The instructions to setup the RESTful Engine via Tomcat Server can be found here.

Send a Request to Run a Document with SQL Data

note

Make sure you know the URL of the RESTful Engine you are using as you will need this to send a request to the engine.

tip

An easy tool to send a request to the RESTful Engine is Postman. You can download Postman here.

The first step to generate a document is to send a POST request to the /v2/document endpoint of your RESTFul Engine setup from the previous steps. For example: http://localhost:8080/v2/document. The body of the request should contain the template and the data you want to use to generate the document. Below is an example of the body of the request in JSON and XML format.

{
"template": {
"connectionString": "{template_connection_string}",
"outputFormat": "pdf",
"datasources": [
{
"name": "{template_db_name}",
"type": "ado",
"className": "com.microsoft.sqlserver.jdbc.SQLServerDriver",
"connectionString": "jdbc:sqlserver://{server_address};databaseName={database_name};username={username};password={password};"
}
]
}
}
<Template>
<ConnectionString>{template_connection_string}</ConnectionString>
<OutputFormat>pdf</OutputFormat>
<Datasources>
<Datasource>
<Name>{template_db_name}</Name>
<Type>ado</Type>
<ClassName>com.microsoft.sqlserver.jdbc.SQLServerDriver</ClassName>
<ConnectionString>jdbc:sqlserver://{server_address};databaseName={database_name};username={username};password={password};</ConnectionString>
</Datasource>
</Datasources>
</Template>

This will return a response with status 200 and the document GUID. You can use this document GUID to check the status of the document and retrieve the document.

danger

If you don't get a response with status 200, check the body of the response for more information on what went wrong. Our swagger documentation can be found here for additional information.

Check the Status of the Document

After you send the request to generate the document, you can check the status of the document by sending a GET request to the /v2/document/{document_guid}/status endpoint of your RESTful Engine setup. For example: http://localhost:8080/v2/document/ba1315d6-7ddc-4b1f-9f14-0999309d5799/status. The response will contain the status of the document. The following status codes are:

  • 302: The document has successfully generated.
  • 201: The document hasn't began processing yet.
  • 202: The document is currently processing.
  • 404: The requested document does not exist.
  • 500: There was an error processing the document.

Once you recieve a status of 302, you can retrieve the document.

Retrieve the Document

To retrieve the document, you will need to send a GET request to the /v2/document/{document_guid} endpoint of your RESTful Engine setup. For example: http://localhost:8080/v2/document/ba1315d6-7ddc-4b1f-9f14-0999309d5799. The response will contain the document base64 data.

tip

If you would like to recieve the file as a download, you can use the /v2/document/{document_guid}/file endpoint. If you place this URL in your browser, it will download the file.

info

For further information about the RESTful Engine, you can check out our swagger documentation here.

tip

If you would like RESTful Engine sample code that contain ready-made templates and datasources, you can find them on our Sample Templates page by clicking the info icon next to the Sample Template you would like to generate.

Congratulations! You have successfully generate a document with SQL data in the Java RESTful Engine.